package com.yilin.medical.activity;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

import com.yilin.medical.R;
import com.yilin.medical.utils.AppUtil;
import com.yilin.medical.utils.JxSystemUtil;

/**
 * 视频会诊详情页,这个页面,没有listview,所以在这里没有使用bean和adapter
 * 
 * @author lijianqun
 * 
 */
public class ShiPinHuiZhenDetailsActivity extends BaseActivity {
	private Context context;
	private ScrollView mScrollView;
	private RelativeLayout mRelativeLayoutWoYaoCanJia;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentViewWithTitle(R.layout.activity_shipinhuizhendetails);
		context = this;
		initView();
		registener();
	}

	private void initView() {
		mTitle.getTitle().setText("病例讨论详情");
		mScrollView = (ScrollView) findViewById(R.id.sv);
		mRelativeLayoutWoYaoCanJia = (RelativeLayout) findViewById(R.id.rl_woyaocanjia);
	}

	private void registener() {
		mRelativeLayoutWoYaoCanJia.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {
		case R.id.rl_woyaocanjia:
			// TODO 弹出确定取消按钮
			showQueDingQuXiaoDialog();
			break;
		}
	}

	private void showQueDingQuXiaoDialog() {

		View layout = ((Activity) context).getLayoutInflater().inflate(
				R.layout.pop_querenxinxi, null);
		final PopupWindow pop = new PopupWindow(layout,
				AppUtil.getScreenWidth(context),
				AppUtil.getScreenHeight(context), false);
		pop.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
		// 设置点击窗口外边窗口消失
		pop.setOutsideTouchable(true);
		// 设置此参数获得焦点，否则无法点击
		pop.setFocusable(true);
		if (JxSystemUtil.isFlymeOs4x()) {
			pop.setHeight(AppUtil.getScreenHeight(context) - JxSystemUtil.getStatusBarHeight(this)
					* 2);
			// 至于这里为什么乘以2，我只能说，除了鬼鬼们，只有魅族自己知道，我是发现获得的StatusBarHeight偏小，所以乘以2，实践检验是正确的，但也很无语
			pop.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM, 0, 0);
		} else {
			pop.setHeight(AppUtil.getScreenHeight(context) - JxSystemUtil.getStatusBarHeight(this));
			pop.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM, 0, 0);
		}

		TranslateAnimation ta = new TranslateAnimation(
				Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
				Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF,
				0);
		ta.setDuration(500);
		layout.startAnimation(ta);
	
	}

	public void setListViewHeightBasedOnChildren(ListView listView) {
		ListAdapter listAdapter = listView.getAdapter();
		if (listAdapter == null) {
			return;
		}

		int totalHeight = 0;
		for (int i = 0; i < listAdapter.getCount(); i++) {
			View listItem = listAdapter.getView(i, null, listView);
			listItem.measure(0, 0);
			totalHeight += listItem.getMeasuredHeight();
		}

		ViewGroup.LayoutParams params = listView.getLayoutParams();
		params.height = totalHeight
				+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
		params.height += 5;
		listView.setLayoutParams(params);
	}

}
